#!/bin/bash
# 测试MySQL主从同步状态
#
USER=root
PASSWD=12345
IO_SQL_STATUS=$(mysql -u$USER -p$USER -p$PASSWD -e 'show slave status \G' |awk -F:'/Slave_.*_Running/{gsub(":",":");print $0}') #gsub去除冒号后面的空格

for i in $IO_SQL_STATUS; do
    THREAD_STATUS_NAME=${I%:*}
    THREAD_STATUS=${I#*:}
    if [ "$THREAD_STATUS" != "Yes" ]; then 
        echo "Error：MySQL Master-Slave $THREAD_STATUS_NAME status is$THREAD_STATUS!""
    fi
done